package pkg

import (
	"encoding/json"
	"github.com/Baidu-AIP/golang-sdk/aip/censor"
)

func VideoReview(file map[string]string, coverURL string) (bool, string) {
	client := censor.NewClient("ZTFnKIKj6OuhLPNlgriC3x03", "PqD3BDpZxIUTYnEOBtjkvBCLDts4gtyQ")

	for _, v := range file {
		if v == "" {
			continue
		}

		res := client.TextCensor(v)

		var data map[string]interface{}
		if err := json.Unmarshal([]byte(res), &data); err != nil {
			// JSON解析失败，也当作不合规
			return false, "解析失败"
		}

		if conclusion, ok := data["conclusion"].(string); ok && conclusion != "合规" {

			return false, "包含违规内容"
		}

	}

	if coverURL != "" {
		res := client.ImgCensor(coverURL, nil)

		var data map[string]interface{}
		if err := json.Unmarshal([]byte(res), &data); err != nil {
			return false, "解析失败"
		}
		if conclusion, ok := data["conclusion"].(string); ok && conclusion != "合规" {
			return false, "包含违规内容"
		}
	}
	return true, ""

}
